﻿using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.EsgResearchProfileLogic;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.Tests.Helpers;
using System.Threading.Tasks;
using Xunit;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.CorporateDataLogic;
using Sustainalytics.SharedEntities.EsgResearch;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.Tests
{
    public class ComprehensiveEsgResearchProfileLogicTests
    {
        private readonly IComprehensiveEsgSyncOrchestrator<EsgResearchProfile> comprehensiveEsgResearchProfileOrchestrator;

        private readonly IComprehensiveEsgCompaniesIdsQuery comprehensiveEsgCompaniesIdsQuery;

        private readonly IComprehensiveEsgResearchProfileQuery comprehenisveEsgResearchProfileQuery;

        public ComprehensiveEsgResearchProfileLogicTests()
        {
            TestLogger logger = new TestLogger();
            var container = SimpleInjectorConfig.Register(logger, TestConnectionStrings.GAConnectionStrings);

            comprehensiveEsgCompaniesIdsQuery = container.GetInstance<EsgCompaniesIdsQuery>();

            comprehenisveEsgResearchProfileQuery = container.GetInstance<EsgResearchProfileQuery>();
            comprehensiveEsgResearchProfileOrchestrator = container.GetInstance<EsgResearchProfileOrchestrator>();
        }

        [Fact]
        public async Task ResolveComprehensiveEsgResearchProfiles()
        {
            var comprehensiveEsgCompaniesIds = await comprehensiveEsgCompaniesIdsQuery.GetAsync();

            var comprehensiveEsgResearchProfileEntities = comprehenisveEsgResearchProfileQuery.Get(comprehensiveEsgCompaniesIds.CompaniesWithActiveResearch);

            await comprehensiveEsgResearchProfileOrchestrator.OrchestrateAsync(comprehensiveEsgResearchProfileEntities, comprehensiveEsgCompaniesIds.InvalidatedCompanies);
        }
    }
}
